package com.wlx.system.controller;

import com.wlx.common.core.utils.SecurityUtils;
import com.wlx.common.core.utils.poi.ExcelUtil;
import com.wlx.common.core.web.controller.BaseController;
import com.wlx.common.core.web.domain.AjaxResult;
import com.wlx.common.core.web.page.TableDataInfo;
import com.wlx.common.log.annotation.Log;
import com.wlx.common.log.enums.BusinessType;
import com.wlx.common.security.annotation.PreAuthorize;
import com.wlx.system.domain.SysApplication;
import com.wlx.system.service.ISysApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 应用信息 应用：指调用当前系统所提供服务的应用或系统；Controller
 *
 * @author admin
 * @date 2021-03-01
 */
@RestController
@RequestMapping("/application")
public class SysApplicationController extends BaseController {
    @Autowired
    private ISysApplicationService sysApplicationService;

    /**
     * 查询应用信息 应用：指调用当前系统所提供服务的应用或系统；列表
     */
    @PreAuthorize(hasPermi = "system:application:list")
    @GetMapping("/list")
    public TableDataInfo list(SysApplication sysApplication) {
        startPage();
        List<SysApplication> list = sysApplicationService.selectSysApplicationList(sysApplication);
        return getDataTable(list);
    }

    /**
     * 导出应用信息 应用：指调用当前系统所提供服务的应用或系统；列表
     */
    @PreAuthorize(hasPermi = "system:application:export")
    @Log(title = "应用信息 应用：指调用当前系统所提供服务的应用或系统；", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysApplication sysApplication) throws IOException {
        List<SysApplication> list = sysApplicationService.selectSysApplicationList(sysApplication);
        ExcelUtil<SysApplication> util = new ExcelUtil<SysApplication>(SysApplication.class);
        util.exportExcel(response, list, "application");
    }

    /**
     * 获取应用信息 应用：指调用当前系统所提供服务的应用或系统；详细信息
     */
    @PreAuthorize(hasPermi = "system:application:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysApplicationService.selectSysApplicationById(id));
    }

    /**
     * 新增应用信息 应用：指调用当前系统所提供服务的应用或系统；
     */
    @PreAuthorize(hasPermi = "system:application:add")
    @Log(title = "应用信息 应用：指调用当前系统所提供服务的应用或系统；", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysApplication sysApplication) {
        sysApplication.setUserCode(SecurityUtils.getUserId().toString());
        return toAjax(sysApplicationService.insertSysApplication(sysApplication));
    }

    /**
     * 修改应用信息 应用：指调用当前系统所提供服务的应用或系统；
     */
    @PreAuthorize(hasPermi = "system:application:edit")
    @Log(title = "应用信息 应用：指调用当前系统所提供服务的应用或系统；", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysApplication sysApplication) {
        return toAjax(sysApplicationService.updateSysApplication(sysApplication));
    }

    /**
     * 删除应用信息 应用：指调用当前系统所提供服务的应用或系统；
     */
    @PreAuthorize(hasPermi = "system:application:remove")
    @Log(title = "应用信息 应用：指调用当前系统所提供服务的应用或系统；", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysApplicationService.deleteSysApplicationByIds(ids));
    }
}